"""
    @Author  ：思念 
    @File    ：4.豆瓣评论.py
    @Date    ：2024/12/4 15:04 
"""

import requests
from lxml import etree


url = "https://movie.douban.com/subject/1292052"

header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0"
}

res = requests.get(url, headers=header)
# print(res.text)
tree = etree.HTML(res.text)

# 若浏览器元素找的属性与页面源代码不一致，直接使用源代码中的属性值
content_list = tree.xpath("//div[@class='review-list  ']//div[@class='short-content']/text()")
print(content_list)

